package com.ltcode.sys.infrastructure.persistence.converter;

import com.ltcode.sys.domain.model.SysDept;
import com.ltcode.sys.infrastructure.persistence.entity.SysDeptPO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 部门对象转换器
 * 
 * @author ltcode
 * @since 2024-01-01
 */
public class SysDeptConverter {

    /**
     * PO转换为领域模型
     */
    public static SysDept toDomain(SysDeptPO po) {
        if (po == null) {
            return null;
        }
        SysDept domain = new SysDept();
        BeanUtils.copyProperties(po, domain);
        return domain;
    }

    /**
     * 领域模型转换为PO
     */
    public static SysDeptPO toPO(SysDept domain) {
        if (domain == null) {
            return null;
        }
        SysDeptPO po = new SysDeptPO();
        BeanUtils.copyProperties(domain, po);
        return po;
    }

    /**
     * PO列表转换为领域模型列表
     */
    public static List<SysDept> toDomainList(List<SysDeptPO> poList) {
        if (poList == null || poList.isEmpty()) {
            return new ArrayList<>();
        }
        List<SysDept> domainList = new ArrayList<>();
        for (SysDeptPO po : poList) {
            domainList.add(toDomain(po));
        }
        return domainList;
    }

    /**
     * 领域模型列表转换为PO列表
     */
    public static List<SysDeptPO> toPOList(List<SysDept> domainList) {
        if (domainList == null || domainList.isEmpty()) {
            return new ArrayList<>();
        }
        List<SysDeptPO> poList = new ArrayList<>();
        for (SysDept domain : domainList) {
            poList.add(toPO(domain));
        }
        return poList;
    }
}
